# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.

### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4

# Home row direction keys, like vim
#set $left h
#set $down j
#set $up k
#set $right l
# Your preferred terminal emulator
set $term foot
set $term2 kitty
# Your preferred application launcher
#set $menu wmenu-run
set $menu wofi -G --show=run

## Swaylock, daemonize, show failed attempts, removed -e for fprintd, set color
set $locker swaylock -f -F -c 2E3436 && sleep 1

## try to force lock on lid close...
## Kill off gpg agent as it isnt recovering sleep power down.
bindswitch --reload --locked lid:on exec bash -c "$locker; gpgconf --kill gpg-agent"

## Lock on demand
## Looks like I would have to remove the hjkl default arrow bindings to use...
bindsym $mod+l exec $locker

font pango:monospace 8
titlebar_padding 1 1

## remove window title bar by setting border low
default_border pixel 2
hide_edge_borders smart

### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
#output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
#
# Example configuration:
#
#   output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs


### Idle Configuration ### {{{
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
#exec swayidle -w \
#    timeout 300 'swaylock -f -F -c 2E3436' \
#    timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
#    before-sleep 'swaylock -f -F -c 2E3436'

#exec swayidle -w timeout 300 'swaylock -f -c 2E3436' timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' before-sleep 'swaylock -f -c 2E3436'
### End Idle Configuration ### }}}

## Handing locking.
## Turns off screen first. Then later locks. Also tries to lock before sleep.
## Using exec_always so that reloading changes work.
exec_always killall swayidle; swayidle -w \
    timeout 300 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
    timeout 600 'swaylock -f -F -c 2E3436' \
    before-sleep 'swaylock -f -F -c 2E3436' \
    lock 'swaylock -f -F -c 2E3436'


### Exec Programs ### {{{
exec wl-paste --watch cliphist store
exec sway-accel-rotate
exec shikane
exec wpaperd -d
exec nm-applet
exec blueman-applet
exec udiskie
exec syncthing
### End Exec Programs ### }}}

### Exec Per Workspace Programs ### {{{
#exec swaymsg "workspace 1; exec kitty;"
exec swaymsg "workspace 1; exec foot;"
### End Exec Per Workspace Programs ### }}}


### Input configuration
#
# Example configuration:
#
#   input "2:14:SynPS/2_Synaptics_TouchPad" {
#       dwt enabled
#       tap enabled
#       natural_scroll enabled
#       middle_emulation enabled
#   }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
input "type:keyboard" xkb_options caps:escape

## hide cursor after time
seat seat0 hide_cursor 3000

## NOTE: use `swaymsg -t get_inputs` to see input devices IDs

## get GPD pocket 4 touchpad (as a 'pointer' device) to scroll sanely
## If using a match all, this messes up normal mice...
#input type:pointer {
input 9610:12:HAILUCK_CO.,LTD_USB_KEYBOARD_Mouse {
    tap enabled
    natural_scroll enabled
}


# Allow switching between workspaces with left and right swipes
#bindgesture swipe:4:right workspace prev
#bindgesture swipe:4:left workspace next

### Key bindings
#
# Basics:
#
    # Start a terminal
    bindsym $mod+Return exec $term
    #bindsym $mod+Shift+Return exec foot
    bindsym $mod+Shift+Return exec $term2

    # Kill focused window
    bindsym $mod+Shift+q kill

    # Start your launcher
    bindsym $mod+d exec $menu
    bindsym $mod+p exec $menu
    bindsym XF86Search exec $menu   ## sofle keyboard

    # Drag floating windows by holding down $mod and left mouse button.
    # Resize them with right mouse button + $mod.
    # Despite the name, also works for non-floating windows.
    # Change normal to inverse to use left mouse button for resizing and right
    # mouse button for dragging.
    floating_modifier $mod normal

    # Reload the configuration file
    bindsym $mod+Shift+c reload

    # Exit sway (logs you out of your Wayland session)
    bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'


## Add a way to hop between most recent workspaces
bindsym $mod+Tab workspace back_and_forth


#
# Moving around:
#
    # Move your focus around
    #bindsym $mod+$left focus left
    #bindsym $mod+$down focus down
    #bindsym $mod+$up focus up
    #bindsym $mod+$right focus right
    # Or use $mod+[up|down|left|right]
    bindsym $mod+Left focus left
    bindsym $mod+Down focus down
    bindsym $mod+Up focus up
    bindsym $mod+Right focus right

    # Move the focused window with the same, but add Shift
    #bindsym $mod+Shift+$left move left
    #bindsym $mod+Shift+$down move down
    #bindsym $mod+Shift+$up move up
    #bindsym $mod+Shift+$right move right
    # Ditto, with arrow keys
    bindsym $mod+Shift+Left move left
    bindsym $mod+Shift+Down move down
    bindsym $mod+Shift+Up move up
    bindsym $mod+Shift+Right move right
#
# Workspaces:
#
    # Switch to workspace
    bindsym $mod+1 workspace number 1
    bindsym $mod+2 workspace number 2
    bindsym $mod+3 workspace number 3
    bindsym $mod+4 workspace number 4
    bindsym $mod+5 workspace number 5
    bindsym $mod+6 workspace number 6
    bindsym $mod+7 workspace number 7
    bindsym $mod+8 workspace number 8
    bindsym $mod+9 workspace number 9
    bindsym $mod+0 workspace number 10
    # Move focused container to workspace
    bindsym $mod+Shift+1 move container to workspace number 1
    bindsym $mod+Shift+2 move container to workspace number 2
    bindsym $mod+Shift+3 move container to workspace number 3
    bindsym $mod+Shift+4 move container to workspace number 4
    bindsym $mod+Shift+5 move container to workspace number 5
    bindsym $mod+Shift+6 move container to workspace number 6
    bindsym $mod+Shift+7 move container to workspace number 7
    bindsym $mod+Shift+8 move container to workspace number 8
    bindsym $mod+Shift+9 move container to workspace number 9
    bindsym $mod+Shift+0 move container to workspace number 10
    # Note: workspaces can have any name you want, not just numbers.
    # We just use 1-10 as the default.
#
# Layout stuff:
#
    # You can "split" the current object of your focus with
    # $mod+b or $mod+v, for horizontal and vertical splits
    # respectively.
    bindsym $mod+b splith
    bindsym $mod+v splitv

    # Switch the current container between different layout styles
    bindsym $mod+s layout stacking
    bindsym $mod+w layout tabbed
    bindsym $mod+e layout toggle split

    # Make the current focus fullscreen
    bindsym $mod+f fullscreen

    # Toggle the current focus between tiling and floating mode
    bindsym $mod+Shift+space floating toggle

    # Swap focus between the tiling area and the floating area
    bindsym $mod+space focus mode_toggle

    # Move focus to the parent container
    bindsym $mod+a focus parent
#
# Scratchpad:
#
    # Sway has a "scratchpad", which is a bag of holding for windows.
    # You can send windows there and get them back later.

    # Move the currently focused window to the scratchpad
    bindsym $mod+Shift+minus move scratchpad

    # Show the next scratchpad window or hide the focused scratchpad window.
    # If there are multiple scratchpad windows, this command cycles through them.
    bindsym $mod+minus scratchpad show



## Move the current workspace to the next output
bindsym $mod+Mod1+Left  move workspace to output Left
bindsym $mod+Mod1+Down  move workspace to output Down
bindsym $mod+Mod1+Up    move workspace to output Up
bindsym $mod+Mod1+Right move workspace to output right

#
# Utilities:
#
    # Special keys to adjust volume via PulseAudio
    bindsym --locked XF86AudioMute              exec pactl set-sink-mute \@DEFAULT_SINK@ toggle
    bindsym --locked XF86AudioLowerVolume       exec pactl set-sink-volume \@DEFAULT_SINK@ -5%
    bindsym --locked XF86AudioRaiseVolume       exec pactl set-sink-volume \@DEFAULT_SINK@ +5%
    bindsym --locked Shift+XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -1%
    bindsym --locked Shift+XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +1%
    bindsym --locked $mod+XF86AudioLowerVolume  exec pactl set-sink-volume \@DEFAULT_SINK@ 1%
    bindsym --locked $mod+XF86AudioRaiseVolume  exec pactl set-sink-volume \@DEFAULT_SINK@ 100%
    bindsym --locked XF86AudioMicMute           exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle
    bindsym --locked Shift+XF86AudioMute        exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle

    ## push to talk
    bindsym --no-repeat $mod+z                      exec pactl set-source-mute \@DEFAULT_SOURCE@ 0      ## Hold to talk, generic
    bindsym --no-repeat --release $mod+z            exec pactl set-source-mute \@DEFAULT_SOURCE@ 1      ## Release to mute, generic
    bindsym --no-repeat $mod+Shift+z                exec pactl set-source-mute \@DEFAULT_SOURCE@ 0      ## Unmute, generic
    bindsym --no-repeat XF86PickupPhone             exec pactl set-source-mute \@DEFAULT_SOURCE@ 0      ## Hold to talk
    bindsym --no-repeat --release XF86PickupPhone   exec pactl set-source-mute \@DEFAULT_SOURCE@ 1      ## Release to mute
    bindsym --no-repeat XF86Go                      exec pactl set-source-mute \@DEFAULT_SOURCE@ 0      ## Hold to talk, x1carb11
    bindsym --no-repeat --release XF86Go            exec pactl set-source-mute \@DEFAULT_SOURCE@ 1      ## Release to mute, x1carb11

    # Special keys to adjust brightness via brightnessctl
    bindsym --locked XF86MonBrightnessDown          exec brightnessctl set 5%-
    bindsym --locked XF86MonBrightnessUp            exec brightnessctl set 5%+
    bindsym --locked Shift+XF86MonBrightnessDown    exec brightnessctl set 1%-
    bindsym --locked Shift+XF86MonBrightnessUp      exec brightnessctl set 1%+
    bindsym --locked $mod+XF86MonBrightnessDown     exec brightnessctl set 1%
    bindsym --locked $mod+XF86MonBrightnessUP       exec brightnessctl set 100%


    ## Take a screenshot with grimshot
    bindsym Print       exec grimshot save window ~/temp/$(date +%Y%m%d-%H%M%S)_screen.png
    bindsym Shift+Print exec grimshot save area ~/temp/$(date +%Y%m%d-%H%M%S)_screen.png
    bindsym Ctrl+Print  exec grimshot save area ~/temp/$(date +%Y%m%d-%H%M%S)_screen.png


    ## wofi bindings
    bindsym $mod+Shift+p exec wofi-pass -t
    bindsym Shift+XF86Search exec wofi-pass -t  ## sofle keyboard
    bindsym $mod+c exec cliphist list | wofi -S dmenu | cliphist decode | wl-copy


### Sway Modes ### {{{
    ### Resize Container Mode ### {{{
    mode "resize" {
        # left will shrink the containers width
        # right will grow the containers width
        # up will shrink the containers height
        # down will grow the containers height
        #bindsym $left   resize shrink width 10px
        #bindsym $down   resize grow height 10px
        #bindsym $up     resize shrink height 10px
        #bindsym $right  resize grow width 10px

        # Ditto, with arrow keys
        bindsym Left    resize shrink width 10px
        bindsym Down    resize grow height 10px
        bindsym Up      resize shrink height 10px
        bindsym Right   resize grow width 10px

        # Return to default mode
        bindsym Return mode "default"
        bindsym Escape mode "default"
    }
    bindsym $mod+r mode "resize"
    ### End Resize Container Mode ### }}}

    ### system-control Mode ### {{{
    mode "system-control" {
        bindsym l exec $locker, mode "default"
        bindsym s exec $locker && systemctl suspend, mode "default"
        bindsym h exec $locker && systemctl hibernate, mode "default"
        bindsym e exec swaynag -t warning -m 'Are you sure you want to exit sway?' -B 'Yes, exit sway' 'swaymsg exit'

        ## Set brightness to my default of 30% (for pocket4)
        bindsym b exec brightnessctl set 30%, mode "default"

        ## Return to default mode
        bindsym Return mode "default"
        bindsym Escape mode "default"
    }

    ## GPD Pocket
    bindsym $mod+Print mode "system-control"
    bindsym $mod+Pause mode "system-control"
    bindsym $mod+End mode "system-control"
    ## x270
    #bindsym XF86Tools mode "system-control"
    ## x1nano and sofle keyboard
    bindsym XF86Favorites mode "system-control"
    ### End system-control Mode ### }}}

    ### Wallpaper Mode ### {{{
    mode "wallpaper" {
        bindsym n       exec wpaperctl next
        bindsym Right   exec wpaperctl next
        bindsym p       exec wpaperctl previous
        bindsym Left    exec wpaperctl previous
        bindsym Space   exec wpaperctl toggle-pause
        bindsym r       exec wpaperctl reload

        ## Return to default mode
        bindsym Return mode "default"
        bindsym Escape mode "default"
    }
    bindsym $mod+shift+w mode "wallpaper"
    ### End Wallpaper Mode ### }}}

    ### Control playerctl Mode ### {{{
    bindsym XF86AudioPlay exec playerctl --ignore-player=firefox,chromium play-pause
    bindsym XF86AudioNext exec playerctl --ignore-player=firefox,chromium previous
    bindsym XF86AudioPrev exec playerctl --ignore-player=firefox,chromium next

    mode "control-playerctl" {
    ## Escape the comma in ignore, to not break the mode reversion
        bindsym space   exec playerctl --ignore-player=firefox\,chromium play-pause, mode "default"
        bindsym p       exec playerctl --ignore-player=firefox\,chromium play, mode "default"
        bindsym s       exec playerctl --ignore-player=firefox\,chromium stop, mode "default"
        bindsym q       exec playerctl --ignore-player=firefox\,chromium stop, mode "default"
        bindsym comma   exec playerctl --ignore-player=firefox\,chromium previous, mode "default"
        bindsym period  exec playerctl --ignore-player=firefox\,chromium next, mode "default"
        bindsym less    exec playerctl --ignore-player=firefox\,chromium previous, mode "default"
        bindsym greater exec playerctl --ignore-player=firefox\,chromium next, mode "default"
        bindsym Left    exec playerctl --ignore-player=firefox\,chromium previous, mode "default"
        bindsym Right   exec playerctl --ignore-player=firefox\,chromium next, mode "default"

        ## back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym Escape mode "default"
    }

    bindsym $mod+m mode "control-playerctl"
    ### End Control playerctl Mode ### }}}
### End Sway Modes ### }}}

### Bar Settings ### {{{
bar {
    swaybar_command waybar
}
### End Bar Settings ### }}}

### Window Treatments
for_window [class = "Pqiv"] floating enable
for_window [class = "Pinentry-gtk"] floating enable
for_window [app_id = "gamescope"] floating enable


include /etc/sway/config.d/*
